﻿using System.Windows;

namespace SHomeWorkshop.LunarPresentation.Commands
{
    public partial class Command
    {
        public static void Align(Expressions.Expression.Alignment align)
        {
            if (Globals.selectedEditor == null) return;
            if (Globals.selectedEditor.SelectedExpression == null) return;

            LunarPresentation.Expressions.Expression curEx
                = Globals.selectedEditor.SelectedExpression;

            //2011年7月2日尝试令子面板控制其中公式的默认对齐方式。
            //if (curEx is Expressions.SubPanel)
            //{
            //    MessageBox.Show("子面板不支持设置“对齐方式”！", Globals.appName,
            //        MessageBoxButton.OK, MessageBoxImage.Warning);
            //    return;//子面板不支持设置对齐方式。
            //}

            if (curEx is Expressions.BaseText)
            {
                Expressions.BaseText curBt = curEx as Expressions.BaseText;
                if (curBt.IsCollapsed)
                {
                    MessageBox.Show("折叠的标题文本块不能更改对齐方式。此外“剪切、粘贴、删除、平移、拖动、更改缩进”等操作亦被禁止。",
                        Globals.appName, MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }
            }

            Expressions.Expression ex = Globals.selectedEditor.SelectedExpression;

            ModifingItem mi = new ModifingItem();
            Action action = new Action(ex.ExID, -1, ex.GetType().Name, "Align", ex.Align.ToString(),
                align.ToString());

            ex.Align = align;

            Globals.RefreshMainWindowIndentButtonsStatus(Globals.MainWindow, true, ex);
            Globals.RefreshAlignButtonsStatus(Globals.MainWindow,/* true,*/ ex);

            mi.Add(action);
            ex.Editor.Do(mi);
        }
    }
}
